<?php
/**
 * User: yuesir
 * Date: 2016/4/27
 * Time: 22:00
 */
namespace Lib\Database;
use Lib\IDatabase;

class MySQLi implements  IDatabase
{
    protected $conn;
    /**
     * 连接数据库
     * @param $host
     * @param $user
     * @param $passwd
     * @param $dbname
     */
    function connect($host, $user, $passwd, $dbname)
    {
        $this->conn = new \mysqli("localhost", "root", "", "test");
        if($this->conn->connect_errno) {
            printf("Connect failed: %s\n", $this->conn->connect_errno);
            exit();
        }
    }

    /**
     * 查询数据库
     * @param $sql
     */
    function query($sql)
    {
        $res = $this->conn->query($sql);
        //var_dump($res);
        //$res = $res->fetch_assoc();
        return $res;
    }

    /**
     * 关闭数据库
     */
    function close()
    {
        $this->conn->close($this->conn);
    }
}